//
//  sdl_event_display.c
//  FFmpegDemo
//
//  Created by xiaerfei on 2019/4/6.
//  Copyright © 2019 erfeixia. All rights reserved.
//

#include "sdl_event_display.h"
#include <SDL2/SDL.h>

void sdl_event_display(void) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window *window = SDL_CreateWindow("sdl diplay", 200, 200, 640, 480, SDL_WINDOW_SHOWN);
    
    if (window == NULL) {
        printf("创建 window 失败 ！！！");
        goto __exit;
    }
    
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
    if (renderer == NULL) {
        printf("创建 renderer 失败 ！！！");
        goto __desWin;
    }
    
    int quit = 1;
    do {
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        SDL_Event event;
        SDL_WaitEvent(&event);
        switch (event.type) {
            case SDL_QUIT:
                quit = 0;
                break;
                
            default:
                printf("event: %d",event.type);
                break;
        }
        
    } while (quit);
    
    
    
    //    SDL_Delay(15000);
    
    
__desWin:
    SDL_DestroyWindow(window);
    
__exit:
    SDL_Quit();
}


